import useSiteConfig, { useBoxList } from '@/hooks/api/useSiteConfig'
import useSiteSearchStore from '@/store/hooks/useSiteSearchStore'
import useSiteSettingsStore from '@/store/hooks/useSiteSettingsStore'
import { useWeatherData } from './useWeather'

const useSiteData = () => {
  const { site_config, search_config, loading: site_config_loading } = useSiteConfig()
  const user_id = ref(-1)
  const siteSettingsStore = useSiteSettingsStore()
  const siteSearchStore = useSiteSearchStore()

  watch(
    () => site_config.value?.user_id,
    (id) => {
      console.log(id)
      if (!id) return
      user_id.value = id
      siteSettingsStore.load(site_config.value)
      siteSearchStore.load(search_config.value)
    }
  )


  const { box_list, loading: box_list_loading } = useBoxList(user_id)

  const { weather_data, loading: weather_loading } = useWeatherData()

  return {
    site_config,
    search_config,
    site_config_loading,
    box_list,
    box_list_loading
  }
}

export default useSiteData
